<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改推荐')"/>
    <th:block th:include="include :: datetimepicker-css"/>
    <th:block th:include="include :: summernote-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-recommend-edit" th:object="${recommend}">
        <input name="id" th:field="*{id}" type="hidden">
        <div class="form-group">
            <label class="col-sm-3 control-label">推送的时间：</label>
            <div class="col-sm-8">
                <div class="input-group date">
                    <input name="sendTime" th:value="${#dates.format(recommend.sendTime, 'yyyy-MM-dd')}"
                           class="form-control" placeholder="yyyy-MM-dd" type="text">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">推荐描述文字摘要：</label>
            <div class="col-sm-8">
                <input name="content" class="form-control" type="text" th:field="*{content}">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">判断是否已推送：</label>
            <div class="col-sm-8">
                <select name="isSend" th:field="*{isSend}">
                    <option value="0">是</option>
                    <option value="1">否</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-8">
                <input type="hidden" name="appids" id="appids" th:field="*{appids}">
            </div>
        </div>
    </form>
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>序列号：</label>
                                <input type="text" name="serialNum"/>
                            </li>
                            <li>
                                <label>应用名称：</label>
                                <input type="text" name="name"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                        class="fa fa-search"></i>&nbsp;搜索</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: datetimepicker-js"/>
<th:block th:include="include :: summernote-js"/>
<script th:inline="javascript">
    var prefix = ctx + "system/recommend";
    $("#form-recommend-edit").validate({
        focusCleanup: true
    });

    function submitHandler() {
        console.log("1---->" + $('#appids').val());
        table.set();
        var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
        if (rows.length != 0) {
            $('#appids').val(rows.join());
            console.log("2---->" + $('#appids').val());
        }
        if ($.validate.form()) {
            $.operate.save(prefix + "/edit", $('#form-recommend-edit').serialize());
        }
    }

    $("input[name='addtime']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });

    $("input[name='sendTime']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });

    $(function () {
        $('.summernote').each(function (i) {
            $('#' + this.id).summernote({
                lang: 'zh-CN',
                callbacks: {
                    onChange: function (contents, $edittable) {
                        $("input[name='" + this.id + "']").val(contents);
                    },
                    onImageUpload: function (files) {
                        var obj = this;
                        var data = new FormData();
                        data.append("file", files[0]);
                        $.ajax({
                            type: "post",
                            url: ctx + "common/upload",
                            data: data,
                            cache: false,
                            contentType: false,
                            processData: false,
                            dataType: 'json',
                            success: function (result) {
                                if (result.code == web_status.SUCCESS) {
                                    $('#' + obj.id).summernote('insertImage', result.url);
                                } else {
                                    $.modal.alertError(result.msg);
                                }
                            },
                            error: function (error) {
                                $.modal.alertWarning("图片上传失败。");
                            }
                        });
                    }
                }
            });
            var content = $("input[name='" + this.id + "']").val();
            $('#' + this.id).summernote('code', content);
        })
    });

    var prefix2 = ctx + "system/appsys";
    $(function () {

        var options = {
            url: prefix2 + "/list",
            uniqueId: '',
            modalName: "应用详细内容",
            pageSize: 2000,
            pagination: false,
            showRefresh: false,
            clickToSelect: true,
            columns: [
                {
                    field: 'checked',
                    checkbox: true,
                    formatter: function (value, row, index) {
                        var arr = $('#appids').val().split(",");
                        for (var i = 0; i < arr.length; i++) {
                            if (arr[i] == row.id) {
                                return true;
                            }
                        }
                        return false;
                    }
                }, {
                    field: 'id',
                    title: 'id',
                    visible: false
                },
                {
                    field: 'serialNum',
                    title: '序列号：'
                },
                {
                    field: 'name',
                    title: '应用名称'
                },
                {
                    field: 'url',
                    title: '网址'
                }
            ]
        };
        $.table.init(options);


    });
</script>
</body>
</html>
